import {db} from "@/lib/db";

export async function searchArticle(query: string) {
    if (!query) return [];
    return db.$queryRaw`
        SELECT art_title,art_content,art_source,art_url,created_at FROM tb_article WHERE art_title &@~ ${query} AND created_at >= current_timestamp-'6 hours'::interval ORDER BY created_at desc   
    `;
}

export async function searchQA(query: string) {
    if (!query) return [];
    return db.$queryRaw`
    select 
        case when zt=1 or prev_lbn>=1 then '1' else '' end has_zt,
        reply_time,
        qa.secu_code,qa.secu_name,
        price,
        ltsz,ask_mess,reply_mess,reply_time 
    from tb_qa as qa  left join v_expect as dc on qa.secu_code=dc.secu_code
    where 1=1 
        and (price*1.21>high_100)
        and not qa.secu_name &@~ 'ST' and not starts_with(qa.secu_code,'688')
        and  reply_mess &@~ ${query}
    order by reply_time desc
    limit 100
    `;
}